﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Hosting;
using Configuration.ServerApi.Param;
using Configuration.ServerApi.Service;
using System.Threading.Tasks;

namespace Configuration.ServerApi.Controllers
{
    /// <summary>
    /// 材料数据库相关Controller
    /// </summary>
    [Authorize("AuthJwt")]
    [Route("api/[controller]")]
    [ApiController]
    public class MaterialController : ControllerBase
    {
        private readonly IHostEnvironment HostEnvironment;
        private readonly IMaterialService MaterialService;

        #region 构造函数

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="hostEnvironment"></param>
        /// <param name="materialService"></param>
        public MaterialController(IHostEnvironment hostEnvironment,
            IMaterialService materialService)
        {
            HostEnvironment = hostEnvironment;
            MaterialService = materialService;
        }

        #endregion

        #region 获取材料数据列表

        /// <summary>
        /// 获取材料数据列表
        /// </summary>
        /// <param name="param">搜索条件</param>
        /// <returns>JSON结果集</returns>
        [HttpPost]
        [Route("MaterialList")]
        public async Task<IActionResult> MaterialList(SearchModel param)
        {
            return await MaterialService.MaterialList(param);
        }

        #endregion

        #region 获取材料数据详情

        /// <summary>
        /// 获取材料数据详情
        /// </summary>
        /// <param name="param">搜索条件</param>
        /// <returns>JSON结果集</returns>
        [HttpPost]
        [Route("MaterialDetail")]
        public async Task<IActionResult> MaterialDetail(SearchModel param)
        {
            return await MaterialService.MaterialDetail(param);
        }

        #endregion

    }
}
